cmake_minimum_required(VERSION 3.4)
# 查找 protobuf库文件
find_package(Protobuf REQUIRED)
if (PROTOBUF_FOUND)
    message("protobuf found")
else ()
    message(FATAL_ERROR "Cannot find Protobuf")
endif ()

# 编译 proto 为 .cpp 和 .h，存放在 PROTO_SRCS
set(PROTO_FILES proto/simple.proto)
FILE(GLOB protofiles "${CMAKE_CURRENT_SOURCE_DIR}/proto/*.proto")
PROTOBUF_GENERATE_CPP(PROTO_SRCS PROTO_HDRS ${protofiles})
message("PROTO_SRCS = ${PROTO_SRCS}")
message("PROTO_HDRS = ${PROTO_HDRS}")

# 关联 protobuf 到最后的二进制文件
add_executable(${PROJECT_NAME}
        main.cc
        ${PROTO_SRCS}
        ${PROTO_HDRS})

target_include_directories(${PROJECT_NAME}
        PUBLIC ${CMAKE_CURRENT_BINARY_DIR}
        PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}
        PUBLIC ${PROTOBUF_INCLUDE_DIRS})

target_link_libraries(${PROJECT_NAME} ${PROTOBUF_LIBRARIES})
